package main.controller.admin;

import main.RequestHelper;
import main.TimeHelper;
import main.database.AccountHelper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class AuthorAddPageController {
    @RequestMapping (value = "/authoradd")
    public String authorAdd(HttpServletRequest request, ModelMap modelMap) {
        String uuid = RequestHelper.getUserUUIDFromRequest(request);
        boolean isAdmin = AccountHelper.isAdminFromUUID(uuid);
        String account = AccountHelper.getAccountInfoFromUUID(uuid);

        if (!isAdmin) {
            return "admin/adminLoginPage";
        }
        else {
            modelMap.put("year2year", TimeHelper.getFormattedYear2Year());
            modelMap.put("userName", account);
            return "admin/authorAddPage";
        }
    }
}
